package com.yanqu.road.server.cmd.activity.ghost;

import com.yanqu.road.entity.union.UnionMember;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.pb.activity.GhostActivityProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;
import java.util.Map;

@Cmd(code = GameProtocol.S_GHOST_SYNC_RED_HOT_FROM_CROSS, desc = "鬼市跨服同步红点")
public class GhostSyncRedHotFromCross implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        GhostActivityProto.CrossGhostSyncRedHotReqMsg reqMsg = GhostActivityProto.CrossGhostSyncRedHotReqMsg.parseFrom(packet.getBytes());
        String unionUid = reqMsg.getUnionUid();
        List<Long> noUserIdList = reqMsg.getNoUserIdList();
        Map<Long, CrossUnionMember> unionMemberMap = CrossUnionMgr.getUnionMemberMap(unionUid);

        for (UnionMember member : unionMemberMap.values()) {
            if(noUserIdList.contains(member.getUserId())){
                continue;
            }
            GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(member.getUserId());
            if (onlinePlayer != null) {
                GhostActivityProto.SyncGhostUnionNewsRespMsg.Builder builder = GhostActivityProto.SyncGhostUnionNewsRespMsg.newBuilder();
                onlinePlayer.sendPacket(ClientProtocol.U_GHOST_SYNC_RED_HOT, builder);
            }
        }

    }
}
